/*
Copyright 2010,2011 Matt Van Der Westhuizen

This file is part of CGLL.

CGLL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

CGLL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with CGLL.  If not, see <http://www.gnu.org/licenses/>.
*/

package org.chaoticengine.cgll.entity.component.cleanup;

import java.util.HashMap;
import java.util.Map;
import org.chaoticengine.cgll.entity.component.ActiveComponent;
import org.chaoticengine.cgll.input.Command;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.Shape;
import org.newdawn.slick.state.StateBasedGame;
import org.simpleframework.xml.Root;

/**
 * A fairly simple component to destroy transient entities like bullets
 * as soon as they no longer appear on the screen.
 *
 * @author Matt v.d. Westhuizen
 */
@Root
public class ExpireComponent extends ActiveComponent {

    private Map<String, Command> commands = new HashMap<String, Command>();
    
    public ExpireComponent() {
    }

    @Override
    public Map<String, Command> getCommands() {
        return(commands);
    }

    @Override
    public void update(GameContainer gc, StateBasedGame sb, int delta) {
        // No commands that can be active, so calling super is unnecessary
        //super.update(gc, sb, delta);

        Shape scr = new Rectangle(0.0f, 0.0f, gc.getWidth(), gc.getHeight());
        if (!scr.intersects(owner.getBounds())) {
            getOwner().destroy();
        }
    }
}
